/**
 * https://leetcode-cn.com/problems/summary-ranges/
 * 汇总区间
 * @param nums 
 */
const summaryRanges = (nums: number[]): string[] => {
    const len = nums.length;

    if (len === 0) return []

    let v = nums[0],
        po = 0,
        s = 1,
        ans: string[] = []

    while (s < len) {
        let curr = nums[s]
        // 相等
        if (curr !== v + 1) {
            // 不相等
            // 将po 到 (s - 1)部分加入数组中
            let cs: string = s - po > 1 ? `${nums[po]}->${nums[s - 1]}` : `${nums[po]}`

            ans.push(cs)

            // 更新po,s
            po = s
        }
        v = curr
        s++
    }

    // 最后一个也要放入数组中
    ans.push(s - po > 1 ? `${nums[po]}->${nums[s - 1]}` : `${nums[po]}`)


    return ans
};

console.log(summaryRanges([0, 2, 3, 4, 6, 8, 9]))
console.log(summaryRanges([0, 1, 2, 4, 5, 7]))
console.log(summaryRanges([1]))